<?php
/**
 * Setting_akun Class
 */
class Setting_akun extends CI_Controller {
	/**
	 * Constructor, load Semester_model, Cabang_model
	 */
	function Setting_akun()
	{
		parent::__construct();
		$this->load->model('Setting_akun_model', '', TRUE);
		$this->load->model('Home_model', '', TRUE);
	}
	/**
	 * Iid_userialisasi variabel untuk $title(untuk id element <body>), dan */
	var $title = 'Setting Akun';
	
	/**
	 * Memeriksa user state,
	 * jika tidak akan meredirect ke halaman login
	 */
	function index()
	{
		//cek nih user udah login apa blom, kalo blom lempar ke halaman login
		if ($this->session->userdata('login') == FALSE)
		{
			redirect('auth');
		}
		$id_role = $this->session->userdata('id_role'); 
		$id_user = $this->session->userdata('id_user'); 
				
		$data['hak_akses0'] = $this->Home_model->get_hak_akses($id_role,0);
		$data['hak_akses1'] = $this->Home_model->get_hak_akses($id_role,1);
		$data['hak_akses2'] = $this->Home_model->get_hak_akses($id_role,2);
		
		$data['title'] = $this->title;
		$data['main_view'] = 'setting_akun/setting_akun_view';
		$data['form_action'] = 'setting_akun/update_akun';
		
		$data_akun = $this->Setting_akun_model->get_akun_by_id($id_user);
		
		$data['default']['nama']	 	= $data_akun->NAMA;
		$data['default']['email'] 	  	= $data_akun->EMAIL;
		$data['default']['username']	= $data_akun->USERNAME;
		
		// Load view
		$this->load->view('template', $data);
	}
	
	function update_akun(){
		
		$id_user = $this->session->userdata('id_user'); 
		$password	= md5($this->input->post('password'));
		
		$data_user = array(
			'NAMA'		=> $this->input->post('nama'),
			'USERNAME'	=> $this->input->post('username'),
			'EMAIL'		=> $this->input->post('email')
		);
		
		$this->Setting_akun_model->update_akun($id_user,$data_user);
		
		// set message
		$this->session->set_flashdata('message', 'Profil berhasil diupdate!');
		redirect('setting_akun');
	}
	
	
	
}
	
	